<?php
/**
 * Created by PhpStorm.
 * User: xiong <1099446868@qq.com>
 * DateTime: 2019/3/13
 * TIME: 22:42
 */

namespace app\Console;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\console\input\Argument;
use think\console\input\Option;

class Hello extends Command{
    protected function configure()
    {
        $this->setName('hello')  //命令名
            ->addArgument('name', Argument::OPTIONAL, "your name")     //参数
            ->addOption('city', null, Option::VALUE_REQUIRED, 'city name') //选项
            ->setDescription('Say Hello');  //描述
    }

    protected function execute(Input $input, Output $output)
    {
        $name = trim($input->getArgument('name'));
        $name = $name ?: 'thinkphp';

        if ($input->hasOption('city')) {
            $city = PHP_EOL . 'From ' . $input->getOption('city');
        } else {
            $city = '';
        }

        $output->writeln("Hello," . $name . '!' . $city);
    }
}